home *** CD-ROM | disk | FTP | other *** search
/ Aminet 32 / Aminet 32 (1999)(Schatztruhe)[!][Aug 1999].iso / Aminet / dev / lang / Python151_Src.lha / Python1.5_Source / Parser / intrcheck.c < prev    next >
C/C++ Source or Header  |  1998-01-25  |  5KB  |  245 lines

  1. /***********************************************************
  2. Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
  3. The Netherlands.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its
  8. documentation for any purpose and without fee is hereby granted,
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in
  11. supporting documentation, and that the names of Stichting Mathematisch
  12. Centrum or CWI or Corporation for National Research Initiatives or
  13. CNRI not be used in advertising or publicity pertaining to
  14. distribution of the software without specific, written prior
  15. permission.
  16.  
  17. While CWI is the initial source for this software, a modified version
  18. is made available by the Corporation for National Research Initiatives
  19. (CNRI) at the Internet address ftp://ftp.python.org.
  20.  
  21. STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
  22. REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
  23. MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
  24. CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
  25. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  26. PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  27. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  28. PERFORMANCE OF THIS SOFTWARE.
  29.  
  30. ******************************************************************/
  31.  
  32. /* Check for interrupts */
  33.  
  34. #include "config.h"
  35. #include "myproto.h"
  36. #include "mymalloc.h" /* For ANY */
  37. #include "intrcheck.h"
  38. #ifdef HAVE_FCNTL_H
  39. #include <fcntl.h>
  40. #endif
  41. #include "protos/intrcheck_protos.h"
  42.  
  43. /* Copied here from ceval.h -- can't include that file. */
  44. int Py_AddPendingCall Py_PROTO((int (*func) Py_PROTO((ANY *)), ANY *arg));
  45.  
  46.  
  47. #ifdef QUICKWIN
  48.  
  49. #include <io.h>
  50.  
  51. void
  52. PyOS_InitInterrupts()
  53. {
  54. }
  55.  
  56. void
  57. PyOS_FiniInterrupts()
  58. {
  59. }
  60.  
  61. int
  62. PyOS_InterruptOccurred()
  63. {
  64.     _wyield();
  65. }
  66.  
  67. #define OK
  68.  
  69. #endif /* QUICKWIN */
  70.  
  71. #if defined(_M_IX86) && !defined(__QNX__)
  72. #include <io.h>
  73. #endif
  74.  
  75. #if defined(MSDOS) && !defined(QUICKWIN)
  76.  
  77. #ifdef __GNUC__
  78.  
  79. /* This is for DJGPP's GO32 extender.  I don't know how to trap
  80.  * control-C  (There's no API for ctrl-C, and I don't want to mess with
  81.  * the interrupt vectors.)  However, this DOES catch control-break.
  82.  * --Amrit
  83.  */
  84.  
  85. #include <go32.h>
  86.  
  87. void
  88. PyOS_InitInterrupts()
  89. {
  90.     _go32_want_ctrl_break(1 /* TRUE */);
  91. }
  92.  
  93. void
  94. PyOS_FiniInterrupts()
  95. {
  96. }
  97.  
  98. int
  99. PyOS_InterruptOccurred()
  100. {
  101.     return _go32_was_ctrl_break_hit();
  102. }
  103.  
  104. #else /* !__GNUC__ */
  105.  
  106. /* This might work for MS-DOS (untested though): */
  107.  
  108. void
  109. PyOS_InitInterrupts()
  110. {
  111. }
  112.  
  113. void
  114. PyOS_FiniInterrupts()
  115. {
  116. }
  117.  
  118. int
  119. PyOS_InterruptOccurred()
  120. {
  121.     int interrupted = 0;
  122.     while (kbhit()) {
  123.         if (getch() == '\003')
  124.             interrupted = 1;
  125.     }
  126.     return interrupted;
  127. }
  128.  
  129. #endif /* __GNUC__ */
  130.  
  131. #define OK
  132.  
  133. #endif /* MSDOS && !QUICKWIN */
  134.  
  135.  
  136. #ifdef macintosh
  137.  
  138. /* The Mac interrupt code has moved to macglue.c */
  139. #define OK
  140.  
  141. #endif /* macintosh */
  142.  
  143.  
  144. #ifndef OK
  145.  
  146. /* Default version -- for real operating systems and for Standard C */
  147.  
  148. #include <stdio.h>
  149. #include <string.h>
  150. #include <signal.h>
  151. #ifdef HAVE_UNISTD_H
  152. #include <unistd.h>
  153. #endif
  154.  
  155. static int interrupted;
  156.  
  157. void
  158. PyErr_SetInterrupt()
  159. {
  160.     interrupted = 1;
  161. }
  162.  
  163. extern int PyErr_CheckSignals();
  164.  
  165. /* ARGSUSED */
  166. static RETSIGTYPE
  167. #if defined(_AMIGA) || defined(_M_IX86) && !defined(__QNX__)
  168. intcatcher(int sig)    /* So the C compiler shuts up */
  169. #else /* _M_IX86 */
  170. intcatcher(sig)
  171.     int sig; /* Not used by required by interface */
  172. #endif /* _M_IX86 */
  173. {
  174.     extern void Py_Exit Py_PROTO((int));
  175.     static char message[] =
  176. "python: to interrupt a truly hanging Python program, interrupt once more.\n";
  177.     switch (interrupted++) {
  178.     case 0:
  179.         break;
  180.     case 1:
  181.         write(2, message, strlen(message));
  182.         break;
  183.     case 2:
  184.         interrupted = 0;
  185.         Py_Exit(1);
  186.         break;
  187.     }
  188.     signal(SIGINT, intcatcher);
  189.     Py_AddPendingCall(PyErr_CheckSignals, NULL);
  190. }
  191.  
  192. static RETSIGTYPE (*old_siginthandler)() = SIG_DFL;
  193.  
  194. void
  195. PyOS_InitInterrupts()
  196. {
  197.     if ((old_siginthandler = signal(SIGINT, SIG_IGN)) != SIG_IGN)
  198.         signal(SIGINT, intcatcher);
  199. #ifdef HAVE_SIGINTERRUPT
  200.     /* This is for SunOS and other modern BSD derivatives.
  201.        It means that system calls (like read()) are not restarted
  202.        after an interrupt.  This is necessary so interrupting a
  203.        read() or readline() call works as expected.
  204.        XXX On old BSD (pure 4.2 or older) you may have to do this
  205.        differently! */
  206.     siginterrupt(SIGINT, 1);
  207. #endif /* HAVE_SIGINTERRUPT */
  208. }
  209.  
  210. void
  211. PyOS_FiniInterrupts()
  212. {
  213.     signal(SIGINT, old_siginthandler);
  214. }
  215.  
  216. int
  217. PyOS_InterruptOccurred()
  218. {
  219. #ifdef __SASC
  220.     extern void __regargs __chkabort(void);
  221.     extern void chkabort(void);
  222.  
  223.     chkabort();        /* explicit Amiga SAS/C ^C check */
  224. #endif
  225.     if (!interrupted)
  226.         return 0;
  227.     interrupted = 0;
  228.     return 1;
  229. }
  230.  
  231. #ifdef __SASC
  232. /* Amiga SAS/C replacement ^C handler */
  233. void __regargs _CXBRK(void)
  234. {
  235.     interrupted=1;
  236. }
  237. #endif
  238.  
  239. #endif /* !OK */
  240.  
  241. void
  242. PyOS_AfterFork()
  243. {
  244. }
  245.